package com.ymdd.library.pickerview.adapter;

import android.content.Context;

import com.ymdd.library.pickerview.utils.PickerConfig;
import com.ymdd.library.pickerview.utils.Utils;
import com.ymdd.library.pickerview.utils.WheelCalendar;

import java.util.Date;

/**
 * Created by 000098 on 2019/3/26。
 * Description
 *
 * @author 000098
 */
public class WeekAdapter extends WeekNumericWheelAdapter{

    public WeekAdapter(Context context) {
        super(context);
    }

    public WeekAdapter(Context context, int minValue, int maxValue) {
        super(context, minValue, maxValue);
    }

    public WeekAdapter(Context context, int minValue, int maxValue, String format) {
        super(context, minValue, maxValue, format);
    }

    public WeekAdapter(Context context, int minValue, int maxValue, String format, String unit , PickerConfig config) {
        super(context, minValue, maxValue, format, unit);

        WheelCalendar mMinCalendar = config.mMinCalendar;
        long millseconds = mMinCalendar.millseconds;
        for (int i = 0; i <= maxValue; i++) {
            days.add(Utils.getDayText(new Date(millseconds) , i));
            times.add(Utils.getTimeText(new Date(millseconds) , i));
        }
    }

    @Override
    public Object getItem(int index) {

        if (index >= 0 && index < getItemsCount()) {
            return days.get(index);
        }
        return null;
    }

    @Override
    public int indexOf(Object o) {
        String text = o.toString();
        int i = days.indexOf(text);

        try {
            return i- minValue;
        } catch (Exception e) {
            return -1;
        }
    }
}
